package top.humbleyuan.sortmethod;

import top.humbleyuan.leet.Array;

import java.util.Arrays;

/**
 * @Author HumbleYuan
 * @Date 2020/2/15 11:28
 * @Des 冒泡排序
 */
public class Bubble {
    public static void main(String[] args) {
        int[] array = {3,12,14,3,6,1,9};

        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }

    /**
     * 每次将最大/最小浮到最后
     * @param array
     */
    public static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if(array[i] > array[j]) {
                    int temp = array[j];
                    array[j] = array[i];
                    array[i] = temp;
                }
            }
        }

        System.out.println(Arrays.toString(array));
    }
}
